﻿using TraumaCenterSystem.Code.Bll;
using TraumaCenterSystem.Core;
using TraumaCenterSystem.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TraumaCenterSystem.Areas.TraumaCenter.Controllers
{
    public class QualityPointController : BaseController
    {
        static DataTable AllPoint;
        //
        // GET: /TraumaCenter/QualityPoint/

        public ActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 诊疗路径列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Search()
        {
            OperateResult resultInfo = PathwayManager.GetQualityPointList();
            if (resultInfo.Body.GetType().Name == "DataTable")
            {
                AllPoint = resultInfo.Body as DataTable;
            }
            var res = new { Rows = resultInfo.Body };
            return JsonDate(res);
        }


        public ActionResult GetAllPoint()
        {
            //JsonResult rst = Json(AllPoint);//"[{ id: \"1\", text: \"品牌一\" }, { id: \"2\", text: \"品牌二\" }]"
            //rst.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return JsonDate(AllPoint);
        }

        /// <summary>
        /// 添加/编辑路径
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit(string Id)
        {
            //新增 赋空
            DataTable dt = AllPoint.Clone();
            DataRow dr = AllPoint.Select("Id=" + Id)[0];
            dt.Rows.Add(dr.ItemArray);
            ViewBag.Data = dt;
            return View();
        }

        /// <summary>
        /// 保存新增或者编辑信息
        /// </summary>
        /// <returns></returns>
        public ActionResult EditSubmit()
        {
            string QualityPointTitle = WebUtils.GetString("QualityPointTitle");
            string id = WebUtils.GetString("Id");
            string ComparePointId = WebUtils.GetString("ComparePointId");
            string OverTime = WebUtils.GetString("OverTime");
            string Sort = WebUtils.GetString("Sort");
            string Status = WebUtils.GetString("Status");

            OperateResult result = PathwayManager.SaveQualityPoint(id, QualityPointTitle, ComparePointId, OverTime, Sort, Status, "");
            return Content(result.Body.ToString());

        }

        public ActionResult ChangeStatus()
        {
            string QualityPointTitle = WebUtils.GetString("QualityPointTitle");
            string id = WebUtils.GetString("Id");
            string Status = WebUtils.GetString("Status");

            OperateResult result = PathwayManager.ChangeStatus(id, Status);
            return Content(result.Body.ToString());

        }


    }
}
